/* 
    This file is part of the OdinMS Maple Story Server 
    Copyright (C) 2008 Patrick Huy <patrick.huy@frz.cc> 
                       Matthias Butz <matze@odinms.de> 
                       Jan Christian Meyer <vimes@odinms.de> 

    This program is free software: you can redistribute it and/or modify 
    it under the terms of the GNU Affero General Public License version 3 
    as published by the Free Software Foundation. You may not use, modify 
    or distribute this program under any other version of the 
    GNU Affero General Public License. 

    This program is distributed in the hope that it will be useful, 
    but WITHOUT ANY WARRANTY; without even the implied warranty of 
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
    GNU Affero General Public License for more details. 

    You should have received a copy of the GNU Affero General Public License 
    along with this program.  If not, see <http://www.gnu.org/licenses/>. 
*/ 

//CREATED BY SNOW/SUPERRAZ777 

package net.sf.odinms.client.messages.commands;


import java.util.List; 
import java.util.LinkedList; 
import java.util.ArrayList; 
import java.io.File; 

import net.sf.odinms.client.MapleClient; 
import net.sf.odinms.client.messages.IllegalCommandSyntaxException; 
import net.sf.odinms.client.messages.MessageCallback; 
import net.sf.odinms.tools.Pair; 
import net.sf.odinms.tools.StringUtil; 

import net.sf.odinms.provider.MapleData; 
import net.sf.odinms.provider.MapleDataProvider; 
import net.sf.odinms.provider.MapleDataTool; 
import net.sf.odinms.provider.MapleDataProviderFactory;   

import net.sf.odinms.client.messages.Command; 
import net.sf.odinms.client.messages.CommandDefinition; 


public class findmobcommand implements Command {
    @SuppressWarnings("static-access") 
    @Override 
    public void execute(MapleClient c, MessageCallback mc, String[] splitted) throws Exception, 
                                                                                    IllegalCommandSyntaxException { 
         
if (splitted[0].equals("!findmob")){ 
            String search = StringUtil.joinStringFrom(splitted, 1); 
            List<String> retMobs = new ArrayList<String>(); 
            MapleData data = null; 
            MapleDataProvider dataProvider = MapleDataProviderFactory.getDataProvider(new File(System.getProperty("net.sf.odinms.wzpath") + "/String.wz")); 
            data = dataProvider.getData("Mob.img"); 
            List<Pair<Integer, String>> mobPairList = new LinkedList<Pair<Integer, String>>(); 
           mobPairList.add(new Pair<Integer, String>(0, "CREATED BY SNOW/SUPERRAZ777")); 
    for(MapleData mobIdData : data.getChildren()) { 
        int mobIdFromData = Integer.parseInt(mobIdData.getName()); 
        String mobNameFromData = MapleDataTool.getString(mobIdData.getChildByPath("name"), "NO-NAME"); 
        mobPairList.add(new Pair<Integer, String>(mobIdFromData, mobNameFromData)); 
    } 
    for(Pair<Integer, String> mobPair : mobPairList) { 
    if(mobPair.getRight().toLowerCase().contains(search.toLowerCase())) { 
        retMobs.add(mobPair.getLeft() + " - " + mobPair.getRight()); 
    } 
    } 
    if(retMobs != null && retMobs.size() > 1) { 
            for(String singleRetMob : retMobs) { 
                mc.dropMessage(singleRetMob); 
            } 
            } else { 
            mc.dropMessage("No mobs fit your search criteria"); 
            } 
}   
  
 } 
            @Override 
    public CommandDefinition[] getDefinition() { 
        return new CommandDefinition[] { 
            new CommandDefinition("findmob", "", "", 1000), 


                        

        }; 
    } 

 }  